package com.chezai.client.server;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;

import com.chezai.client.global.Const;
import com.chezai.client.global.TerminalApplication;
import com.chezai.client.server.util.TransmissionMessageUtil;
import com.chezai.client.utils.PreferenceManager;
import com.chezai.client.utils.ToastUtil;
import com.jx.driving.protocol.terminal.channel.Channel;
import com.jx.driving.response.AbstractResponse;
import com.jx.driving.response.Terminal0x8001Response;

import org.greenrobot.eventbus.EventBus;


/**
 * 协议接收监听接口实现类
 * Created by likunyang on 2017/8/24.
 */

public class ChannelListenerImpl_8001 implements ChannelListener {
//    private static final int AUTH_SUCESS = 0;
//    private static final int AUTH_FAILED = 1;
//    private CustomHandler customHandler;
//    private TransmissionMessageUtil messageUtil;

    ChannelListenerImpl_8001() {
//        customHandler = new CustomHandler(Looper.getMainLooper());
//        messageUtil = new TransmissionMessageUtil();
    }

    @Override
    public void active(Channel c) {
//        EventBus.getDefault().postSticky(Const.CHANNEL_ACTIVE);
//        if (PreferenceManager.isRegister()) {
//            TerminalSocketClientManager.getInstance().authenTicate();
//        }
    }

    @Override
    public void inactive(Channel c) {
//        EventBus.getDefault().postSticky(Const.CHANNEL_INACTIVE);
//        customHandler.sendEmptyMessage(Const.CHANNEL_INACTIVE);
//        TerminalSocketClientManager.getInstance().setAuthenticated(false);
    }

    @Override
    public void onReceive(Channel c, Object msg) {
        Log.e("harisucici", "onReceive_8001:" + msg.toString());
        //服务器端返回通用应答
        if (msg instanceof AbstractResponse) {
            AbstractResponse abstractResponse = (AbstractResponse) msg;
            int msgId = abstractResponse.getId();
            Log.e("harisucici", "msgId_8001:" + msgId);
        }
    }


//    class CustomHandler extends Handler {
//        CustomHandler(Looper looper) {
//            super(looper);
//        }
//
//        @Override
//        public void handleMessage(Message msg) {
//            super.handleMessage(msg);
//            switch (msg.what) {
//                case AUTH_SUCESS:
//                    ToastUtil.showToast(TerminalApplication.getTerminalContext(), "鉴权成功！");
//                    break;
//                case AUTH_FAILED:
//                    ToastUtil.showToast(TerminalApplication.getTerminalContext(), "鉴权失败请重试");
//                    break;
//                case Const.CHANNEL_INACTIVE:
//                    ToastUtil.showToast(TerminalApplication.getTerminalContext(), "与服务器断开连接");
//                    break;
//                default:
//                    break;
//            }
//        }
//    }
}
